package DataModel.LayoutManager;

import java.awt.Point;
import java.util.LinkedList;

import DataModel.CommonLibrary.CommonDefs.Layer;

/**
 * Basic Polygon class. Holds all it's coordinates
 * 
 * @author evgeni
 *
 */
public class CPolygon 
{
	/***************************************************/
	/****** C'tors *************************************/
	/***************************************************/
	public CPolygon()
	{
		m_pointsList = new LinkedList<Point>();
	}
	
	public CPolygon(LinkedList<Point> list)
	{
		setPointsList(list);
	}
	
	
	/***************************************************/
	/****** Members ************************************/
	/***************************************************/
	private LinkedList<Point> m_pointsList;

	
	/***************************************************/
	/****** Getters / Setters **************************/
	/***************************************************/
	public LinkedList<Point> getPointsList() {
		return m_pointsList;
	}


	public void setPointsList(LinkedList<Point> list) {
		m_pointsList = list;
	}
	
	public int getPointsCount()
	{
		return m_pointsList.size();
	}
	
	/***************************************************/
	/****** Public functions  **************************/
	/***************************************************/	
	public long GetArea()
	{
		long area = 0;
		LinkedList<CRectangle> recsList = this.ToRectangles();
		
		for (CRectangle rectangle : recsList) 
			area += rectangle.getArea();
		
		return area;
	}
	
	public boolean IsRectangle()
	{
		if(m_pointsList.size() == 2)
			return true;

		return false;
	}
	
	/***************************************************/
	//TODO: FIX FUNCTIONS BELLOW
	/***************************************************/
	public LinkedList<CRectangle> ToRectangles()
	{
		LinkedList<CRectangle> recsList = new LinkedList<CRectangle>();
		
		recsList.add(new CRectangle(
				m_pointsList.get(0).x,m_pointsList.get(0).y,
				m_pointsList.get(1).x,m_pointsList.get(1).y,
				Layer.None,-1));
		
		return recsList;
	}
	
	public long GetPerimiter()
	{
		return this.ToRectangles().get(0).getPerimeter();
	}
}















